home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / server / scripts / racing.cs < prev    next >
Text File  |  2005-11-23  |  2KB  |  75 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //-----------------------------------------------------------------------------
  7. //  Functions that implement game-play
  8. //-----------------------------------------------------------------------------
  9.  
  10. //-----------------------------------------------------------------------------
  11.  
  12. package RacingGame {
  13.  
  14. //-----------------------------------------------------------------------------
  15.  
  16. function GameConnection::onClientEnterGame(%this)
  17. {
  18.    commandToClient(%this, 'SyncClock', $Sim::Time - $Game::StartTime);
  19.    commandToClient(%this, 'SetGameGUI',"RacingGUI");
  20.  
  21.    // Create a new camera object.
  22.    %this.camera = new Camera() {
  23.       dataBlock = Observer;
  24.    };
  25.    MissionCleanup.add( %this.camera );
  26.    %this.camera.scopeToClient(%this);
  27.  
  28.    // Spawn the player
  29.    %this.score = 0;
  30.    %this.spawnPlayer();
  31. }
  32.  
  33. //-----------------------------------------------------------------------------
  34.  
  35. function GameConnection::createPlayer(%this, %spawnPoint)
  36. {
  37.    if (%this.player > 0)  {
  38.       // The client should not have a player currently
  39.       // assigned.  Assigning a new one could result in 
  40.       // a player ghost.
  41.       error( "Attempting to create an angus ghost!" );
  42.    }
  43.  
  44.    %player = new WheeledVehicle() {
  45.       dataBlock = DefaultCar;
  46.       client = %this;
  47.    };
  48.  
  49.    MissionCleanup.add(%player);
  50.  
  51.    // Car setup...
  52.    %player.setTransform(%spawnPoint);
  53.    %player.setShapeName(%this.name);
  54.    
  55.    // Update the camera to start with the car
  56.    %this.camera.setTransform(%player.getEyeTransform());
  57.  
  58.    // Give the client control of the car
  59.    %this.player = %player;
  60.    %this.setControlObject(%player);
  61. }
  62.  
  63.  
  64. //-----------------------------------------------------------------------------
  65.  
  66. function serverCmdSuicide(%client)
  67. {
  68.    if (isObject(%client.player)) {
  69.       %client.player.delete();
  70.       %client.player = 0;
  71.    }
  72.    %client.spawnPlayer();
  73. }
  74.  
  75. };